function getImgToBase64(url, callback) {
  var canvas = document.createElement('canvas'),
    ctx = canvas.getContext('2d'),
    img = new Image()
  img.crossOrigin = '*'
  img.src = url
  img.addEventListener('load', function (e) {
    canvas.height = img.height
    canvas.width = img.width
    ctx.drawImage(img, 0, 0)
    var dataURL = canvas.toDataURL('image/png')
    callback(dataURL)
    canvas = null
  })
}

function dataURLtoFile(dataurl, filename) {
  var arr = dataurl.split(','),
    mime = arr[0].match(/:(.*?);/)[1],
    bstr = atob(arr[1]),
    n = bstr.length,
    u8arr = new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  return new File([u8arr], filename, { type: mime })
}

function getFile(url, filename) {
  let file
  getImgToBase64(url, function (data) {
    file = dataURLtoFile(data, filename)
  })
  return file
}

function transferimgtobase64(url) {
  let canvas = document.createElement('canvas'),
    image = new Image()
  image.src = url
  const ctx = canvas.getContext('2d')
  ctx.clearRect(0, 0, 148, 148)
  ctx.drawImage(image, 0, 0, 148, 148)
  const url1 = canvas.toDataURL('image/jpg', 1)
  var arr = url1.split(','),
    mime = arr[0].match(/:(.*?);/)[1],
    bstr = atob(arr[1]),
    n = bstr.length,
    u8arr = new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  const aaaa = new File([u8arr], 'avatar', { type: mime })
  this.form.avatarArray.push(aaaa)
}
